package com.howells.time.module.first.presenter;

import com.howells.time.base.http.HttpURL;
import com.howells.time.base.http.HttpUtils;
import com.howells.time.base.http.JsonCallback;
import com.howells.time.module.first.view.FirstView;
import com.howells.time.module.main.model.User;
import com.orhanobut.logger.Logger;

import java.util.Map;

import okhttp3.Call;

/**
 * Created by Administrator on 2016.3.20.
 */
public class FirstPresenterImp implements FirstPresenter {

    private FirstView firstView;
    public FirstPresenterImp(FirstView t){
        this.firstView=t;
    }

    @Override
    public void jumplogin() {
        firstView.jumpSuccess();
    }

    @Override
    public void jumpmain(User info) {
        HttpUtils.PostObject(HttpURL.LoginApi.toString(), info, new JsonCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Logger.d(e);
                firstView.resultMsg("网络错误");
                firstView.jumpMain();
            }

            @Override
            public void onResponse(Map<String, Object> response, int id) {
                Logger.d(response);
                if(response.get("message").equals("success")){
                    firstView.jumpMain();
                }else {
                    Logger.e(response.toString());
                    firstView.resultMsg(response.toString());
                    firstView.jumpMain();
                }
            }
        });
    }
}
